package com.wl.cloud.common.model;

import com.mysql.cj.conf.ConnectionUrl;
import lombok.Data;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @author: wanglin
 * @date: 2023-06-12 周一
 * @Version: 1.0
 * @Description:
 */
@Data
public class DatasourceModel implements Serializable {
    static final long serialVersionUID = -5515846944416881264L;

    /**
     * Database Name
     */
    protected String databaseName = null;
    /**
     * 数据库类型，如: mysql,hive...
     */
    protected String type = null;

    /**
     * Character Encoding
     */
    protected String encoding = null;

    /**
     * The JDBC URL
     */
    protected String url = null;

    /**
     * Hostname
     */
    protected String hostName = null;

    /**
     * Port number
     */
    protected int port = ConnectionUrl.DEFAULT_PORT;

    /**
     * User name
     */
    protected String username = null;

    /**
     * Password
     */
    protected String password = null;
    /**
     * dbName
     */
    private String dbName = null;

    protected String description = "Custom Data Source";

    /**
     * Default no-arg constructor for Serialization
     */
    public DatasourceModel() {

    }

    public DatasourceModel(String databaseName, String url, String username, String password) {
        this.databaseName = databaseName;
        this.url = url;
        this.username = username;
        this.password = password;
    }

    public Connection getConnection() throws SQLException {
        return DriverManager.getConnection(url, username, password);
    }
//
//    public Connection getConnection(String usernamename, String password) throws SQLException {
//        return null;
//    }
}
